package com.xyht.sca_s.student_manage_system.modules.assetConsumable.controller;


import com.xyht.sca_s.student_manage_system.auth.util.JwtTokenUtil;
import com.xyht.sca_s.student_manage_system.common.commonReturn.ResponseResult;
import com.xyht.sca_s.student_manage_system.common.desEncodeAndDecode.annotation.SecretBody;
import com.xyht.sca_s.student_manage_system.modules.assetConsumable.entity.SmsAssetConsumableReturnApply;
import com.xyht.sca_s.student_manage_system.modules.assetConsumable.entity.req.SmsAssetConsumableReturnApplyAllowReq;
import com.xyht.sca_s.student_manage_system.modules.assetConsumable.entity.req.SmsAssetConsumableReturnApplyReq;
import com.xyht.sca_s.student_manage_system.modules.assetConsumable.service.SmsAssetConsumableReturnApplyService;
import com.xyht.sca_s.student_manage_system.modules.assetConsumableBorrow.entity.req.SmsAssetConsumableBorrowApplyAllowReq;
import com.xyht.sca_s.student_manage_system.modules.assetConsumableBorrow.entity.req.SmsAssetConsumableBorrowApplyReq;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 * 低值易耗品归还申请 前端控制器
 * </p>
 *
 * @author XYHT
 * @since 2024-09-25
 */
@RestController
@RequestMapping("/assetConsumable/return")
@SecretBody
public class SmsAssetConsumableReturnApplyController {

    @Resource
    private SmsAssetConsumableReturnApplyService smsAssetConsumableReturnApplyService;
    @Resource
    private JwtTokenUtil jwtTokenUtil;


    @ApiOperation(value = "新增易耗品归还申请")
    @PostMapping("/add")
    public ResponseResult smsAssetConsumableReturnApplyAdd(@RequestBody SmsAssetConsumableReturnApplyReq applyReq, HttpServletRequest request) {
        String userId = jwtTokenUtil.getUserIdByRequest(request);
        return smsAssetConsumableReturnApplyService.smsAssetConsumableReturnApplyAdd(applyReq, userId);
    }

    @ApiOperation(value = "撤销易耗品归还")
    @PostMapping("/cancel")
    public ResponseResult smsAssetConsumableReturnApplyCancel(@RequestBody SmsAssetConsumableReturnApplyReq cancelReq, HttpServletRequest request) {
        String userId = jwtTokenUtil.getUserIdByRequest(request);
        return smsAssetConsumableReturnApplyService.smsAssetConsumableReturnApplyCancel(cancelReq, userId);
    }

    @ApiOperation(value = "审批")
    @PostMapping("/allow")
    public ResponseResult smsAssetConsumableReturnApplyAllow(@RequestBody SmsAssetConsumableReturnApplyAllowReq allowReq, HttpServletRequest request) {
        String userId = jwtTokenUtil.getUserIdByRequest(request);
        return smsAssetConsumableReturnApplyService.smsAssetConsumableReturnApplyAllow(allowReq, userId);
    }

    @ApiOperation(value = "审批列表")
    @GetMapping("/list")
    public ResponseResult getAssetConsumableReturnApplyList(@RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
                                                            @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                                            @RequestParam(value = "applyType") Integer applyType,
                                                            HttpServletRequest request) {
        String userId = jwtTokenUtil.getUserIdByRequest(request);
        return smsAssetConsumableReturnApplyService.getAssetConsumableReturnApplyList(pageSize, pageNum, applyType, userId);
    }

    @ApiOperation(value = "审批详情")
    @GetMapping("/detail")
    public ResponseResult getAssetConsumableReturnApplyDetail(@RequestParam(value = "applyId") String applyId, HttpServletRequest request) {
        String userId = jwtTokenUtil.getUserIdByRequest(request);
        return smsAssetConsumableReturnApplyService.getAssetConsumableReturnApplyDetail(applyId, userId);
    }

    @ApiOperation(value = "查询所有申请记录")
    @GetMapping("/selectAll")
    public ResponseResult selectAllAssetConsumableReturnApply(@RequestParam(value = "applyPerson", required = false) String applyPerson,
                                                              @RequestParam(value = "applyDepartment", required = false) String applyDepartment,
                                                              @RequestParam(value = "applyName", required = false) String applyName,
                                                              @RequestParam(value = "allowStatus", required = false) Integer allowStatus,
                                                              @RequestParam(value = "searchStr", required = false) String searchStr,
                                                              @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
                                                              @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum) {
        return smsAssetConsumableReturnApplyService.selectAssetConsumableReturnApply(applyPerson,searchStr, applyDepartment,applyName,allowStatus ,pageSize, pageNum);
    }

}

